salesOpportunitylayui.use(['form','jquery','table','layer'],function(){
    let form = layui.form,
        $ = layui.jquery,
        table = layui.table,
        layer = layui.layer;

    //加载数据表格
    let tabInstance = table.render({
        elem: '#userList',
        url: '/sys-user/list', //数据接口
        page: true, //开启分页
        limit:2, //每页显示的条数，默认10
        limits:[2,5,10,15,], //每页显示条数选择框数据
        request:{
            pageName: 'current',
            limitName: 'size'
        },
        cols: [[ //表头
            {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'},
            {field: 'relName', title: '真实名'},
            {field: 'logName', title: '登录名'},
            {field: 'status', title: '状态'},
            {field: 'tel', title: '联系方式'},
            {field: 'email', title: '邮箱'},
            {field: 'roleName', title: '角色'},
            {field: 'deptName', title: '部门'},
            {field: 'createTime', title: '入职时间'},
            {title: '操作', width: 135,fixed:'right',toolbar:"#userTool"}
        ]]
    });

    //搜索监听启用
    form.on('submit(search)',function(data){
        tabInstance.reload({
            where :data.field
        });
        return false;
    });

    //工具栏操作
    table.on('tool(userList)',function(obj){
        switch (obj.event){
            case 'edit_btn':
                //编辑
                break;
            case 'del_btn':
                layer.confirm('你确定要删除【'+obj.data.relName+'】吗？',{icon:3,anim: 4,skin:'layui-layer-molv'},function(){
                    $.post('sys-user/del/'+obj.data.id,function(data){
                        tabInstance.reload();
                        layer.msg(data.msg);
                    });
                });
        }
    });

    //添加
    $(".add_btn").click(function(){
        layer.open({
            type: 2,
            content: 'views/user/edit.jsp',
            skin:'layui-layer-molv',
            title:"用户管理",
            area:["600px","340px"],
            btn:['确定','关闭'],
            yes: function(index, layero){
                //user_edit
                let user_form = layer.getChildFrame('body', index).find("#user_edit");
                let data = {};
                //把数组转为JSON
                user_form.serializeArray().forEach(function(val){
                    data[val.name] = val.value;
                });
                $.post('sys-user/save-edit',data,function(info){
                    layer.close(index);
                    layer.msg(info.msg);
                    tabInstance.reload();
                });
            }
        });


    });










});